import Router from 'koa-router';
import query from '../utils/query';
import jwt from 'jsonwebtoken'
const router = new Router();
router.prefix('/v1');
const login = async (ctx:Router.RouterContext, next:any) => {
    let {name,pwd}:any=ctx.request.body;
    let sql=await query(`select * from login where user='${name}' and 'pass=${pwd}'`);
    if(sql){
        let token=jwt.sign({name,pwd},'logInf',{expiresIn:'50s'});
        ctx.body={
            code:200,
            msg:'登陆成功',
            token
        }
    }else{
        ctx.body={
            code:100,
            msg:'登录失败',
        }
    }
};
router.post('/login', login);


const string = async (ctx:Router.RouterContext, next:any) => {
    ctx.body = 'welcome to Koa!';
};
router.get('/string', string);
router.post('/string', string);


export default router;
